import { defineStore } from 'pinia'
import { getInfo } from '@/api/user.js'

let lock = false

export const useUserStore = defineStore(
	'user', 
	{
		state: () => ({
			info: {
				id: null,
				openId: null,
				username: null,
				avatar: null,
				sex: null,
				phone: null,
				registerTime: null,
				registrationChannel: null,
				userTag: null,
				emergencyContact: null,
				emergencyContactPhone: null,
				wechat: null,
				orderNum: null,
				status: null
			}
		}),
		actions: {
			getCurrentUser() {
				return this.info
			},
			refreshCurrentUser() {
				getInfo().then(res => {
					Object.assign(this.info, res.data)
					// console.log(this.info)
				})
				
			}
		},
		unistorage: true
	}
)